import type { ArticleResponse } from "./article";
import type { FileReferenceResponse, FileResponse } from "./file";
import { HttpMethod, type DataArrResponse, type HttpRequestRecord as HttpRequestRecord, type ResponseMsg } from "./universal";
import type { UserProfileResponse } from "./user";
  
  /**
   * 声明一个 APIDefinition，用来约束所有 API 的字段
   *    - 如果你想让每个接口的返回数据不同，就在这里给出精准的泛型。
   */
export interface ApiDefinition {
    BASE:string,
    DEFAULT_COS_IMAGE_URL:string;
    COS_LOGIN_IMAGE_URL:string;
    COS_MAIN_LIGHT_IMAGE_URL:string,
    COS_MAIN_DARK_IMAGE_URL:string,
    FILE_UPLOAD: HttpRequestRecord<FileResponse>;
    FILE_QUERY:HttpRequestRecord<DataArrResponse<FileResponse>>;
    FILE_DELETE:HttpRequestRecord<boolean>;
    FILE_QUERY_REFERENCE:HttpRequestRecord<DataArrResponse<FileReferenceResponse>>;
    FILE_CREATE_REFERENCE:HttpRequestRecord<FileReferenceResponse>;
    FILE_DELETE_REFERENCE:HttpRequestRecord<boolean>;
    USER_REGISTER:HttpRequestRecord<object>;
    USER_GRANT_AUTHORIZATION:HttpRequestRecord<string>;
    USER_QUERY_SELF_PROFILE:HttpRequestRecord<UserProfileResponse>;
    USER_QUERY_USER_PROFILE:HttpRequestRecord<DataArrResponse<UserProfileResponse>>;
    USER_MODIFY_SELF_PROFILE:HttpRequestRecord<boolean>;
    USER_DELETE_SELF:HttpRequestRecord<boolean>;
    ARTICLE_QUERY_LIST:HttpRequestRecord<DataArrResponse<ArticleResponse>>;
    ARTICLE_QUERY_DETAIL:HttpRequestRecord<ArticleResponse>;
    ARTICLE_CREATE:HttpRequestRecord<boolean>;
    ARTICLE_MODIFY:HttpRequestRecord<boolean>;
    ARTICLE_DELETE:HttpRequestRecord<boolean>;
  }
  
  /**
   *  API对象 
   */
export const API: ApiDefinition = {
  // 这里修改为HTTPS了 后端基于Nginx做了反向代理了
    BASE:"https://darkskl.site:16555/CoreService",
    DEFAULT_COS_IMAGE_URL:"https://image-1324532138.cos.ap-nanjing.myqcloud.com/67fef7262b005e7b7815cf70.png",
    COS_LOGIN_IMAGE_URL:"https://image-1324532138.cos.ap-nanjing.myqcloud.com/67fe40672b005e7b7815c5b5.jpg",
    COS_MAIN_LIGHT_IMAGE_URL:"https://image-1324532138.cos.ap-nanjing.myqcloud.com/6807961f2b005e7b7815ff5a.jpg",
    COS_MAIN_DARK_IMAGE_URL:"https://image-1324532138.cos.ap-nanjing.myqcloud.com/680795dc2b005e7b7815ff4c.jpg",
    FILE_UPLOAD: {
      URL: "/File:Upload",
      Description: "上传文件",
      Method: HttpMethod.POST,
      IsAuth: true
      // ResponseType: 可选，如果需要在这里放默认结构
    },
    FILE_QUERY:{
      URL:"/File:Query",
      Description:"查询文件",
      Method:HttpMethod.POST,
      IsAuth:false
    },
    FILE_DELETE:{
      URL:"/File:Delete",
      Description:"删除文件",
      Method:HttpMethod.POST,
      IsAuth:true
    }
    ,
    FILE_QUERY_REFERENCE:{
      URL:"/File:QueryReference",
      Description:"查询引用",
      Method:HttpMethod.POST,
      IsAuth:false
    }
    ,
    FILE_CREATE_REFERENCE:{
      URL:"/File:CreateReference",
      Description:"创建引用",
      Method:HttpMethod.POST,
      IsAuth:true
    }
    ,
    FILE_DELETE_REFERENCE:{
      URL:"/File:DeleteReference",
      Description:"删除引用",
      Method:HttpMethod.POST,
      IsAuth:true
    },
    USER_REGISTER:{
        URL:"/User:Register",
        Description:"注册用户",
        Method:HttpMethod.POST,
        IsAuth:true
    },
    USER_GRANT_AUTHORIZATION:{
        URL:"/User:GrantAuthorization",
        Description:"获取授权",
        Method:HttpMethod.GET,
        IsAuth:false
    }
    ,
    USER_QUERY_SELF_PROFILE:{
        URL:"/User:QuerySelfProfile",
        Description:"查询自身资料",
        Method:HttpMethod.GET,
        IsAuth:true
    },
    USER_QUERY_USER_PROFILE:{
      URL:"/User:QueryUserProfile",
      Description:"查询用户资料",
      Method:HttpMethod.POST,
      IsAuth:false
    },
    USER_MODIFY_SELF_PROFILE:{
        URL:"/User:ModifySelfProfile",
        Description:"修改用户自身信息",
        Method:HttpMethod.POST,
        IsAuth:true
    },
    USER_DELETE_SELF:{
      URL:"/User:DeleteSelfUser",
      Description:"删除自身",
      Method:HttpMethod.POST,
      IsAuth:true
    },
    ARTICLE_QUERY_LIST:{
      URL:"/Article:QueryList",
      Description:"查询文章列表",
      Method:HttpMethod.POST,
      IsAuth:false
    },
    ARTICLE_QUERY_DETAIL:{
      URL:"/Article:QueryDetail",
      Description:"查询文章细节",
      Method:HttpMethod.POST,
      IsAuth:false
    },
    ARTICLE_CREATE:{
      URL:"/Article:Create",
      Description:"创建文章",
      Method:HttpMethod.POST,
      IsAuth:true
    },
    ARTICLE_MODIFY:{
      URL:"/Article:Modify",
      Description:"修改文章",
      Method:HttpMethod.POST,
      IsAuth:true
    },
    ARTICLE_DELETE:{
      URL:"/Article:Delete",
      Description:"删除文章",
      Method:HttpMethod.POST,
      IsAuth:true
    }

  };

  
// export const CreateRequest = async <Response,Args extends object>(option:HttpRequestRecord<Response>,args:Args,headers:object):Promise<ResponseMsg<Response> | undefined> =>{
//     let result;
//     switch(option.Method){
//       case HttpMethod.POST: 
//       result = $fetch<ResponseMsg<Response>>(API.BASE+option.URL,{headers:option.IsAuth?authHeaders(headers):{},body:args});
//       break;
//       case HttpMethod.GET:
//       result = $fetch<ResponseMsg<Response>>(API.BASE+option.URL,{headers:option.IsAuth?authHeaders(headers):{},params:args});
//     }
//     return result;
//   }